import marked from 'marked'
import hljs from 'highlight.js'
import { articleSlice } from '@/utils/article.slice'

const renderer = new marked.Renderer()
marked.setOptions({
  renderer: renderer,
  gfm: true, // github 方式
  pedantic: false, // 代码容错
  sanitize: false, // 忽略html
  tables: true, // 可以输出表格
  breaks: false, // 换行符
  smartLists: true, // 渲染列表
  highlight: function (code) {
    return hljs.highlightAuto(code).value
  }
})

export default function (content, number) {
  return number
    ? marked(articleSlice(content, number) || '')
    : marked(content || '')
}
